package GUI;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JLabel;
import javax.swing.JPanel;

import logic.Creator;
import java.awt.Dimension;


public class BoardPanel extends JPanel{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Creator creator;
	public BoardPanel(Creator creator,Cell[][] board) {
		this.creator = creator;
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0};
		gridBagLayout.rowHeights = new int[]{0};
		gridBagLayout.columnWeights = new double[]{Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		 for(int i =0; i< creator.getMat().length;i++)
	        {
	        	for(int j = 0 ; j< creator.getMat().length;j++){
	        		
	        		Cell cell = new Cell();
	        		cell.setBackground(Color.white);
	        		GridBagConstraints gbc_lblCell = new GridBagConstraints();
	        		gbc_lblCell.insets = new Insets(0, 0, 0, 0);
	        		gbc_lblCell.gridx = i;
	        		gbc_lblCell.gridy = j;
	        		add(cell, gbc_lblCell);
	        		
	        		board[i][j] = cell;
	        		cell.addMouseListener(new MouseAdapter() {
						@Override
						public void mousePressed(MouseEvent e) {
							((Cell)e.getSource()).color=CreatorPanel.selectedColor;
							((JPanel)GUI.frame.getContentPane()).revalidate();
							GUI.frame.repaint();
							
						}
					});
	        		
	        	}
	        }
        
        
    }
	 
}
